﻿using Common.Cache.Redis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Common.Cache
{
    public static class CacheExtensions
    {
        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        public static void AddCustomCache(this IServiceCollection services, IConfiguration configuration)
        {
            //redis缓存
            var type = configuration.GetSection("CacheConfig:Type")?.Value;
            type = string.IsNullOrWhiteSpace(type) ? "Redis" : type;
            switch (type)
            {
                case "Redis":
                    var redisConfig = configuration.GetSection("CacheConfig:Redis").Get<RedisConfig>();
                    services.AddSingleton(new RedisHelper(redisConfig));
                    services.AddSingleton<ICustomCache,RedisService>();
                    break;
                default:
                    break;
            }

        }
    }
}
